<?php
/**
 * Created by PhpStorm.
 * User: yangkang
 * Date: 2018/3/14
 * Time: 下午3:08
 */

namespace App\Repositories;


use App\Models\User;

class UserRepository
{
    public function store($user)
    {
        $user = User::create($user);
        $user->save();
    }

    public function getPasswordByMobile($mobile)
    {
        $user = User::where('mobile', '=', $mobile)->first();
        if (!empty($user)) {
            return $user->toArray()['password'];
        } else {
            return false;
        }
    }

    public function getUserByMobile($mobile)
    {
        return User::where('mobile', '=', $mobile)->first();
    }

    public function storeRecord(User $user, $productId, $data)
    {
        $user->records()->updateOrCreate(['product_id' => $productId], $data);
    }
}